//
//  NSDate+XM.m
//  XMWeibo
//
//  Created by chi on 14-8-26.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "NSDate+XM.h"

@implementation NSDate (XM)

- (BOOL)isToday
{
    NSCalendar *cld = [NSCalendar currentCalendar];
    
    NSUInteger uint = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    NSDateComponents *nowCpms = [cld components:uint fromDate:[NSDate date]];
    
    NSDateComponents *selfCpms = [cld components:uint fromDate:self];
    
    
    return nowCpms.year == selfCpms.year
    && nowCpms.month == selfCpms.month
    && nowCpms.day == selfCpms.day;
}


- (BOOL)isThisYear
{
    NSCalendar *cld = [NSCalendar currentCalendar];
    
    NSUInteger uint = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    NSDateComponents *nowCpms = [cld components:uint fromDate:[NSDate date]];
    
    NSDateComponents *selfCpms = [cld components:uint fromDate:self];
    
    return nowCpms.year == selfCpms.year;
}

- (BOOL)isYesterday
{
    NSDateComponents *cmps = [self deltaToNow];
    return /*cmps.hour >= 24 && */cmps.hour < 48 ? YES : NO;
}

- (NSDateComponents *)deltaToNow
{
    NSCalendar *cld = [NSCalendar currentCalendar];
    
    NSUInteger uint = NSCalendarUnitHour | NSCalendarUnitMinute;
    
    return [cld components:uint fromDate:self toDate:[NSDate date] options:0];
}

@end
